package servlet;

import hibernate.User;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import DAO.UserDAO;

/**
 * Servlet implementation class updateUserInfo
 */
public class updateUserInfo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public updateUserInfo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	    request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		HttpSession session = request.getSession();
		String username = session.getAttribute("userName").toString();
		UserDAO user = new UserDAO();
		List list = user.searchUser(username);
		int userId = ((User)list.get(0)).getUserID();
		String id = userId + "";
		String userName = request.getParameter("userName");
		String passWord = request.getParameter("passWord");
		String trueName = request.getParameter("trueName");
		String unit = request.getParameter("unit");
		String job = request.getParameter("job");
		String email = request.getParameter("email");
		String mobilePhone = request.getParameter("mobilePhone");
		String workPhone =request.getParameter("workPhone"); 		
	    user.updateUserInfo(id, userName, passWord, trueName, unit, job, email, mobilePhone, workPhone);
	    out.print("{success:true,msg:'修改成功'}");		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
